# -*- coding: utf8 -*-
#!/usr/bin/python
#
# Copyright (C) 2008 eEcho.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""

module description

models for eTask app

"""

__author__ = 'sergej[A]dergatsjev[D]be (Sergej Dergatsjev)'



from django.contrib import auth
from django.conf import settings
from django.db import models
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.sites.models import Site

from datetime import datetime
import random
import re
import sha


now = datetime.now()
NOW = "%(year)s/%(month)s/%(day)s" % {'year':now.year, 'month':now.month, 'day':now.day}
SHA1_RE = re.compile('^[a-f0-9]{40}$')

PRIORITY = (
           ('Very High','Very High'), 
           ('High','High'), 
           ('Normal','Normal'), 
           ('Low','Low'), 
           ('Very Low','Very Low'), 
            )

STATUS = (
          ('Complete','Complete'),
          ('Incomplete','Incomplete')
          )
           

class TaskCategory(models.Model):
    name = models.CharField(max_length=60, unique=True)
    description = models.CharField(max_length=120, blank=True, null=True)
    def __unicode__(self):
        return u' %(name)s ' % {'name':self.name } 


class Task(models.Model):
    #subtask = models.ManyToManyField("self", symmetrical=False)
    category = models.ForeignKey(TaskCategory)
    name = models.CharField(max_length=120, default="New task")
    priority = models.CharField(max_length=30, choices=PRIORITY, default='Normal')
    status = models.CharField(max_length=30, choices=STATUS, default='Incomplete')
    created = models.DateTimeField(auto_now_add=True)
    completed = models.DateTimeField(blank=True, null=True)
    scheduled_for = models.DateTimeField(auto_now=True, null=True)
    estimated_hour = models.IntegerField(default=1, null=True)
    actual_work_hour = models.IntegerField(default=0, null=True)
    note = models.TextField(blank=True, null=True)        
    assigned_to = models.ForeignKey(auth.models.User)    
    def __unicode__(self):
        return u'%(priority)s %(name)s %(scheduled_for)s'% {"name":self.name, "priority":self.priority, "scheduled_for":self.scheduled_for}    
    class Meta:
        unique_together = (('category', 'name'),)
        get_latest_by = "created"
        ordering = ['-created']
        
        



